/*
 * Copyright (C) 2012 Le Tuan Anh <anh.takaji@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package ezcms.dal.hibernate.mysql;

import ezcms.dal.OrderDAO;
import ezcms.dto.LineItem;
import ezcms.dto.Order;
import ezcms.exceptions.DataLayerException;
import java.util.List;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author Le Tuan Anh <anh.takaji@gmail.com>
 */
class OrderDAOImpl implements OrderDAO {

    public OrderDAOImpl() {
    }

    @Override
    public List<Order> getAllOrders() throws DataLayerException {
        return HibernateUtil.getListByConditions(Order.class, null, "Cannot retrieve all Orders");
    }

    @Override
    public Order getOrderById(long id) throws DataLayerException {
        Object result = HibernateUtil.getObjectById(Order.class, id, "Cannot find Order object with id = " + id);
        return (result == null) ? null : (Order) result;
    }

    @Override
    public void saveOrder(Order order) throws DataLayerException {
        HibernateUtil.saveObject(order, "Cannot save Order");
    }

    @Override
    public void deleteOrder(Order order) throws DataLayerException {
        HibernateUtil.deleteObject(order, "Cannot delete Order");
    }
    
        @Override
    public List<LineItem> getAllLineItems() throws DataLayerException {
        return HibernateUtil.getListByConditions(LineItem.class, null, "Cannot retrieve all LineItems");
    }

    @Override
    public LineItem getLineItemById(long id) throws DataLayerException {
        Object result = HibernateUtil.getObjectById(LineItem.class, id, "Cannot find LineItem object with id = " + id);
        return (result == null) ? null : (LineItem) result;
    }

    @Override
    public void saveLineItem(LineItem lineItem) throws DataLayerException {
        HibernateUtil.saveObject(lineItem, "Cannot save LineItem");
    }

    @Override
    public void deleteLineItem(LineItem lineItem) throws DataLayerException {
        HibernateUtil.deleteObject(lineItem, "Cannot delete LineItem");
    }
}
